<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude"
      py:strip="">
<head py:match="head" py:attrs="select('@*')">
    <meta content="text/html; charset=UTF-8" http-equiv="content-type" py:replace="''"/>
    <title py:replace="''">Your title goes here</title>
    <link py:for="css in tg_css" py:replace="ET(css.display())" />
    <link py:for="js in tg_js_head" py:replace="ET(js.display())" />

    	<style type="text/css">
        #pageLogin
        {
            font-size: 10px;
            font-family: verdana;
            text-align: right;
        }
    </style>
	<script src="/static/javascript/portlet.js" type="text/javascript" />
	<link rel="stylesheet" type="text/css" media="screen" href="/static/css/style.css" />
	<link rel="stylesheet" type="text/css" media="screen" href="/static/css/style-tabs.css" />
	<link rel="stylesheet" type="text/css" media="screen" href="/static/css/style-grey.css" />

	<!-- FUNCTIONS -->
	<!-- tab(wanted) -->
	<py:def function="tab(wanted)">
		<li py:if="this.real_name == wanted" class="tab-grey"><a href="/${wanted}">${this.mapper_tab[wanted]}</a></li>
		<li py:if="this.real_name != wanted"><a href="/${wanted}">${this.mapper_tab[wanted]}</a></li>
	</py:def>

	<!-- portlet_action() -->
	<py:def function="portlet_action()"></py:def>

	<!-- portlet_action_biller() -->
	<py:def function="portlet_action_biller()">
		<div id="actions" class="portlet">
			<h2>${this.mapper_tab['biller']}</h2>
			<ul>
				<li><a href="/biller/+edit">${this.mapper_action['edit']}</a></li>
			</ul>
		</div>
	</py:def>

	<!-- portlet_action_customers() -->
	<py:def function="portlet_action_customers()">
		<div id="actions" class="portlet">
			<h2>${this.mapper_tab['customers']}</h2>
			<ul>
				<li><a href="${tg.url('new')}">${this.mapper_action['new']}</a></li>
			</ul>
		</div>
	</py:def>

	<!-- portlet_action_invoices(has_id=False) -->
	<py:def function="portlet_action_invoices(has_id=False)">
		<div id="actions" class="portlet">
			<h2>${this.mapper_tab['invoices']}</h2>
			<ul>
				<li><a href="${tg.url('new', var='proforma')}">${this.mapper_action['new']} ${this.mapper_general['proforma']}</a></li>
				<li><a href="${tg.url('new', var='invoice')}">${this.mapper_action['new']} ${this.mapper_general['invoice']}</a></li>
				<li py:if="has_id">
					<a href="${tg.url('edit', id=invoice['invoice_id'], var=var)}">
						${this.mapper_action['edit']}
					</a>
				</li>
				<li py:if="has_id">
					<a href="${tg.url('pdf', var=var, id=invoice['invoice_id'])}">
						${this.mapper_action['show']} PDF
					</a>
				</li>
			</ul>
		</div>
	</py:def>

	<!-- portlet_action_projects(has_id=False) -->
	<py:def function="portlet_action_projects(has_id=False)">
		<div id="actions" class="portlet">
			<h2>${this.mapper_tab['projects']}</h2>
			<ul>
				<li><a href="${tg.url('new')}">${this.mapper_action['new']}</a></li>
				<li py:if="has_id"><a href="${tg.url('edit', id=project['project_id'])}">${this.mapper_action['edit']}</a></li>
<li py:if="has_id"><a href="${tg.url('new_milestone', id=project['project_id'])}">${this.mapper_action['new_milestone']}</a></li>
				<li py:if="has_id"><a href="${tg.url('new_task', id=project['project_id'])}">${this.mapper_action['new_task']}</a></li>
			</ul>
		</div>
	</py:def>

	<!-- portlet_action_customers_show() -->
	<py:def function="portlet_action_customers_show()">
		<div id="actions" class="portlet">
			<h2>${this.mapper_general['customer']} #${customer['customer_id']}</h2>
			<ul>
				<li><a href="${tg.url('edit',id=customer['customer_id'])}">${this.mapper_action['edit_customer']}</a></li>
				<li><a href="${tg.url('/invoices/new' ,customer=customer['customer_id'])}">${this.mapper_action['invoice_customer']}</a></li>
			</ul>
		</div>
	</py:def>

	<!-- portlet_login -->
	<py:def function="portlet_login()">
		<py:if test="tg.config('identity.on') and not defined('logging_in')">
			<div class="portlet collapsed" id="portlet-login"><py:if
				test="tg.identity.anonymous">
				<h2 id="portlet-login-h2"><a href="${tg.url('/login')}">Login</a></h2>
			</py:if> <py:if test="not tg.identity.anonymous">
				<h2 id="portlet-login-h2">${tg.identity.user.display_name or tg.identity.user.user_name}</h2>
				<div id="portlet-login-body" class="portletBody">
				<table width="100%">
					<tr>
						<th>User:</th>
						<td>${tg.identity.user.user_name}</td>
					</tr>
					<tr>
						<th>Email:</th>
						<td>${tg.identity.user.email_address}</td>
					</tr>
					<tr>
						<th>Logout:</th>
						<td><a href="/logout"><img src="/static/images/logout.png" alt="Logout" /></a></td>
					</tr>
				</table>
				</div>
			</py:if></div>
		</py:if>
	</py:def>

<py:def function="portlet_tginvoice()">
	<div class="portlet collapsed" id="portlet-release">
		<h2 id="portlet-release-h2">TgInvoice</h2>
		<div id="portlet-release-body" class="portletBody">
		<table width="100%">
			<tr>
				<th>Version:</th>
				<td>${this.release.version}</td>
			</tr>
			<tr>
				<th>License:</th>
				<td>${this.release.license}</td>
			</tr>
			<tr>
				<th>Author:</th>
				<td><a href="mailto:${this.release.email}?subject=[TgInvoice-${this.release.version}]">${this.release.author}</a></td>
			</tr>
			<tr>
				<th>Home Page:</th>
				<td><a href="${this.release.url}"><img src="/static/images/home.png" alt="Home Page" /></a></td>
			</tr>
		</table>
		</div>
	</div>
	<div class="">
	<div class="tab-gray">
	<div class="portlet">
	<div class="center">
		<p>
			<a href="http://validator.w3.org/check?uri=referer">
			<img src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01 Transitional" height="31" width="88" />
			</a>
  		</p>
  		<p>
  			<img src="http://www.w3.org/Icons/valid-css2-blue.png" alt="Valid CSS2" height="31" width="88" />
  		</p>

		<p>
			<a href="http://python.org">
			<img src="/static/images/python-logo-generic.png" alt="Python" height="24" width="88" />
			</a>
  		</p>
	</div>
	</div>
	</div>
	</div>
</py:def>


<py:def function="this_logo()">
	<div id="biller_logo">
		<table py:if="this.pbiller">
		<tr>
			<td><img src="/static/rml/${tg.identity.user.user_name}/logo.png" alt="${tg.identity.user.user_name}"/></td>
			<td>
				<h1>${this.pbiller.company_name}</h1>
				<h3>${this.pbiller.company_slogan}</h3>
			</td>
		</tr>
		</table>
	</div>
</py:def>

<py:def function="this_project()">
	<div id="this_project">
		<h1>${project.name}</h1>
		<big>${project.description}</big>
	</div>
</py:def>

<py:def function="this_biller(has_toggle=True)">
	<div py:if="has_toggle">
    <h4><a onclick="switchMenu('switch-${this.pbiller.company_name}', 'switch-img-${this.pbiller.company_name}');">
    <img id="switch-img-${this.pbiller.company_name}"
    	src="/static/images/leftnav_bg_expanded_small.gif" /></a>
    	${this.pbiller.company_name}</h4>
    </div>
    <div id="switch-${this.pbiller.company_name}">
	<table py:if="this.pbiller" class="summary">
		<tbody>
			<tr py:for="key in this.iterator_biller">
				<th>${this.mapper_biller[key]}:</th>
				<td>${this.pbiller[key]}</td>
			</tr>
		</tbody>
	</table>
	</div>
	<script py:if="has_toggle" var="text/javascript">
		addEvent(window,'load',switchMenu('switch-${this.pbiller.company_name}', 'switch-img-${this.pbiller.company_name}'));
	</script>

</py:def>

<py:def function="this_customer(has_toggle=True)">
	<div py:if="has_toggle">
    <h4><a onclick="switchMenu('switch-${customer.company_name}', 'switch-img-${customer.company_name}');">
    <img id="switch-img-${customer.company_name}"
    	src="/static/images/leftnav_bg_expanded_small.gif" /></a>
    	${customer.company_name}</h4>
    </div>
    <div id="switch-${customer.company_name}">
	<table class="summary">
		<tbody>
			<tr>
				<th>ID:</th>
				<td>${customer['customer_id']}</td>
			</tr>
			<tr py:for="key in this.iterator_customer">
				<th>${this.mapper_customer[key]}:</th>
				<td py:if="key != 'vat_code'">${customer[key]}</td>
				<td py:if="key == 'vat_code'"><a href="${tg.url('/customers/show', id=customer.customer_id)}">${customer[key]}</a></td>
			</tr>
		</tbody>
	</table>
	</div>
	<script py:if="has_toggle" var="text/javascript">
		addEvent(window,'load',switchMenu('switch-${customer.company_name}', 'switch-img-${customer.company_name}'));
	</script>
</py:def>

<py:def function="this_customer_summary()">
	<py:if test="customer.project_customer">
	<h3>${this.mapper_tab['projects']}</h3>
	<ul>
		<li py:for="project in customer.project_customer">
			<p><a href="${tg.url('/projects/show', id=project.project_id)}">${project.name}</a><span>(${project.created})</span></p></li>
	</ul>
	</py:if>
</py:def>

<py:def function="table_products(action=None, has_form=False)">
	<h4>Products</h4>

	<table class="listing">
		<thead>
			<tr>
				 <py:for each="col in this.iterator_product">
				<th py:if="col != 'note'">
					<p>${this.mapper_product[col]}</p>
				</th>
				</py:for>
			</tr>
		</thead>
		<tbody>
			<tr py:for="product in invoice.products">
				<py:for each="val in this.iterator_product">
				<td py:if="val != 'note'">
					<p>
						${product[val]}
						<span py:if="val in ['unit_price', 'tot_price', 'gross_price']">${invoice.currency}</span>
						<span py:if="val == 'vat'">%</span>
						<pre py:if="val == 'description'">${product.product_id} ${product['note']}</pre>
					</p>
				</td>
				</py:for>
				<td>
				<form py:if="has_form" method="get" name="invoice_del_product_form"
					id="invoice_del_product_form" action="${tg.url(action)}">
					<input type="hidden" name="id" value="${invoice.invoice_id}" />
					<input type="hidden" name="var" value="${var}" />
					<input type="hidden" name="del_product" value="${product.product_id}" /> <input
					id="actions.del_product" name="actions.del_product" value="Remove"
					class="button" type="submit" /></form>
				</td>
			</tr>
			<tr py:if="has_form">
				<form method="get" name="invoice_new_product_form" id="invoice_new_form" action="${tg.url(action)}">
				<py:for each="col in this.iterator_product">
				<td py:if="col != 'note'">
					<py:if test="col in this.iterator_product_form">
						<py:if test="col != 'description'">
						<p py:if="col in errors" class="error">${errors[col]}</p>
						<input type="text" size="9" id="new_product.${col}"
						name="new_product.${col}" value="${new_product[col]}"/>
						<span py:if="col == 'unit_price'"> <py:if test="invoice">${invoice.currency}</py:if></span>
						<span py:if="col == 'vat'">%</span>

						</py:if>
						<py:if test="col == 'description'">
						<p py:if="col in errors" class="error">${errors[col]}</p>
						<input type="text" size="40" id="new_product.${col}"
						name="new_product.${col}" value="${new_product[col]}"/>
						<p>${this.mapper_product['note']}</p>
						<textarea id="new_product.note}"
                              name="new_product.note" cols="40" row="3" >${new_product['note']}</textarea>
						</py:if>
					</py:if>
				</td>
				</py:for>
				<td>
				<input type="hidden" name="id" value="${invoice.invoice_id}" />
				<input type="hidden" name="var" value="${var}" />
				<input id="actions.add_product" name="actions.add_product" value="Add" class="button"
				type="submit" />
				</td>
				</form>
			</tr>
		</tbody>
	</table>
	<form py:if="has_form" method="get" name="invoice_save_form"
		id="invoice_save_form" action="${tg.url(action)}">
		<table class="summary">
			<tbody>
						<tr>
					<th>${this.mapper_invoice['created']}</th>
					<td>
						<py:if test="hasattr(invoice, 'created')">${calendar.display()}</py:if>
					</td>
				</tr>
				</tbody>
				</table>
		<input type="hidden" name="id" value="${invoice.invoice_id}" />
		<input type="hidden" name="var" value="${var}" />
		<input id="actions.save" name="actions.save" value="Save" class="button"
				type="submit" />
	</form>
</py:def>

<py:def function="invoice_form(action)">
		<form method="get" name="invoice_form"
			id="invoice_form" action="${tg.url(action)}">
		<table class="summary">
			<tbody>
				<tr>
					<th>${this.mapper_general['customer']}</th>
					<td><select id="customer" name="customer"
						size="1">
						<option py:if="hasattr(invoice,'customer')" value="${invoice.customer.customer_id}">${invoice.customer.customer_id}:
						${invoice.customer.company_name}</option>
						<option value=""></option>
						<option py:for="customer in this.pcustomers"
							value="${customer.customer_id}">${customer.customer_id}:
						${customer.company_name}</option>
					</select></td>
				</tr>
				<py:if test="hasattr(invoice,'customer')">
				<tr>
					<th>${this.mapper_general['currency']}</th>
					<td><select id="currency" name="currency"
						size="1">
						<option py:if="hasattr(invoice, 'currency')" value="${invoice.currency}">${invoice.currency}</option>
						<option value=""></option>
						<option py:for="c in this.iterator_currency" value="${c}">${c}</option>
					</select></td>
				</tr>
				<tr py:if="this.invoice_tmpl">
					<th>${this.mapper_invoice['tmpl']}</th>
					<td><select id="tmpl" name="tmpl"
						size="1">
						<option py:if="hasattr(invoice, 'tmpl')" value="${invoice.tmpl}">${invoice.tmpl}</option>
						<option value=""></option>
						<option py:for="c in this.invoice_tmpl" value="${c}">${c}</option>
					</select></td>
				</tr>
				</py:if>
			</tbody>
		</table>
		<input py:if="invoice" type="hidden" name="id" value="${invoice.invoice_id}" />
		<input type="hidden" name="var" value="${var}" />
		</form>
		<py:if test="invoice">${table_products(action,has_form=True)}</py:if>
	<div class="summary_invoice">
	<table class="summary">
	<tbody>
		<tr>
			<th>Total</th>
			<td>${summary['tot']} <py:if test="invoice">${invoice.currency}</py:if></td>
		</tr>
		<tr py:for="vat in summary['vat']">
			<th>Total (VAT ${vat}%)</th>
			<td>${summary['vat'][vat]} <py:if test="invoice">${invoice.currency}</py:if></td>
		</tr>
		<tr>
			<th>Total (Gross)</th>
			<td>${summary['gross']} <py:if test="invoice">${invoice.currency}</py:if></td>
		</tr>
	</tbody>
	</table>
	</div>
</py:def>

<py:def function="table_milestones(has_form=False)">
	<py:for each="milestone in milestones">
	<big>${milestone.name}</big>
	<i>${milestone.description}</i>
	<table class="listing">
		<thead>
			<tr>
				 <py:for each="col in this.iterator_task">
				<th py:if="col != 'description'">
					<p>${this.mapper_task[col]}</p>
				</th>
				</py:for>
			</tr>
		</thead>
		<tbody>
			<tr py:for="pindex in range(len(milestone.tasks))">
				<py:for each="val in this.iterator_task">
				<td py:if="val != 'description'">
					<p>
						${milestone.tasks[pindex][val]}
					</p>
				</td>
				</py:for>
				<td>
				<form py:if="has_form" method="get" name="invoice_del_task_form"
					id="invoice_del_task_form" action="${tg.url('del_task')}">
				<input type="hidden" name="del_task" value="${pindex}" /> <input
					id="actions.del" name="actions.remove" value="Remove"
					class="button" type="submit" /></form>
				</td>
			</tr>
		</tbody>
	</table>
	<form py:if="has_form" method="get" name="invoice_save_form"
		id="invoice_save_form" action="${tg.url('save')}"><input
		id="actions.save" name="actions.save" value="Save" class="button"
		type="submit" />
	</form>
	</py:for>
</py:def>

    <!-- <meta py:replace="select('*')" />-->


</head>
<body py:match="body" py:attrs="select('@*')">
    <div py:for="js in tg_js_bodytop" py:replace="ET(js.display())" />
    <div py:replace="select('*|text()')" />
    <div py:for="js in tg_js_bodybottom" py:replace="ET(js.display())" />
</body>
</html>
